package Practice;

import java.util.Scanner;

/**
 * create by Sun
 * 2018/8/21
 */
public class bingchajiTest {

    private static int[] arr=new int[1000];
    private static int[] size=new int[1000];
    static int find(int x){
        while(x!=arr[x]){
            x=arr[arr[x]];
        }
        return x;
    }

    static void merge(int x,int y){
         x=find(x);
         y=find(y);
         if(x!=y){
             arr[x]=y;
         }

    }

    public static void main(String[] args) {
        int t;
        Scanner sc=new Scanner(System.in);
        t=sc.nextInt();
        int n,m;
        while(t--!=0){
            n=sc.nextInt();
            m=sc.nextInt();
            for(int i=1;i<=n;i++){
                arr[i]=i;
                size[i]=0;
            }
            int x,y;
            for(int i=0;i<m;i++){
                x=sc.nextInt();
                y=sc.nextInt();
                merge(x,y);
            }
            int sum=0;
            for(int i=1;i<=n;i++){
                if(arr[i]==i){
                    sum++;
                }
            }
            System.out.println(sum);

        }
    }
}
